﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Web;

namespace UnwiseSource
{
    public static class Helper
    {
        public static void LogErrorMsg(string msg)
        {
            try
            {
                string path = "~/" + DateTime.Today.ToString("dd-MM-yy") + ".txt";
                string filePath = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + @"LOGS\";
                if ((filePath != null) || (filePath != ""))
                {
                    path = filePath + DateTime.Today.ToString("dd-MM-yy") + ".txt";
                }
                if (!File.Exists(path))
                {
                    File.Create(path).Close();
                }
                using (StreamWriter w =
                    File.AppendText(path))
                {
                    w.WriteLine("\r\nLog Entry : ");
                    w.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
                    string err = "Error in: " + System.Web.HttpContext.Current.Request.Url.ToString() +
                        ". \n\nError Message: " + msg;
                    w.WriteLine(err);
                    w.WriteLine("===================================");
                    w.Flush();
                    w.Close();
                }
            }
            catch(Exception ex)
            {
               
            }
        }

        public static string getconfigparam(string pname, string defaultvalue = "")
        {
            try
            {
                object ov = ConfigurationManager.AppSettings[pname];
                return ov.ToString();
            }
            catch (Exception ex)
            {
                LogErrorMsg(ex.ToString());
                return defaultvalue;
            }
        }
    }
}